#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define N 10

struct student
{
    int id, score;
};

void findmax(struct student *stu, int *score, int *index)
{
    int i, maxid = 0;
    for (i = 1; i < N; i++)
    {
        if ((stu + i)->score > (stu + maxid)->score)
            maxid = i;
    }
    *score = (stu + maxid)->score;
    *index = maxid;
}

void findmin(struct student *stu, int *score, int *index)
{
    int i, minid = 0;
    for (i = 1; i < N; i++)
    {
        if ((stu + i)->score < (stu + minid)->score)
            minid = i;
    }
    *score = (stu + minid)->score;
    *index = minid;
}

void findaver(struct student *stu, int *score, int *index)
{
    int i, averid = 0, sum = 0;

    //求平均值
    double aver;
    for (sum = 0, i = 0; i < N; i++)
    {
        sum += (stu + i)->score;
    }
    aver = sum / (double)N;

    //找最接近平均值的id
    for (averid = 0, i = 1; i < N; i++)
    {
        if (fabs((stu + i)->score - aver) < fabs((stu + averid)->score - aver))
            averid = i;
    }

    *score = (stu + averid)->score;
    *index = averid;
}

int main()
{
    struct student *stu = NULL;
    stu = (struct student *) malloc ( sizeof(struct student) * N);
    if (stu == NULL)
        return 1;

    int i;
    for (i = 0; i < N; i++)
        scanf("%d%d", &(stu + i)->id, &(stu + i)->score);

    int score, index;

    findmax(stu, &score, &index);
    printf("%d %d\n", (stu + index)->id, score);
    
    findmin(stu, &score, &index);
    printf("%d %d\n", (stu + index)->id, score);
    
    findaver(stu, &score, &index);
    printf("%d %d\n", (stu + index)->id, score);
    
    free(stu);
    stu = NULL; //养成释放指针以后赋值NULL的习惯
    return 0;
}
